home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / movie from dataref / common files / macframework.h < prev    next >
Encoding:
Text File  |  2000-10-06  |  9.5 KB  |  332 lines

  1. //
  2. //    File:        MacFramework.h
  3. //
  4. //    Contains:    Basic functions for windows, menus, and similar things.
  5. //
  6. //    Written by:    Tim Monroe
  7. //                Based on the MovieShell code written by Apple DTS.
  8. //
  9. //    Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //    Change History (most recent first):
  12. //
  13. //       <6>         11/02/98    rtm        minor reworking to coordinate with WinFramework.h
  14. //       <5>         11/07/97    rtm        revised syntax of DoApplicationEventLoopAction
  15. //       <4>         02/26/97    rtm        added fCanEditMovie field to WindowObjectRecord
  16. //       <3>         12/05/96    rtm        added fMovie and fInstance to WindowObjectRecord
  17. //       <2>         11/27/96    rtm        conversion to personal coding style
  18. //       <1>         12/20/94    khs        first file
  19. //       
  20.  
  21. #pragma once
  22.  
  23. // header files
  24.  
  25. #ifndef __APPLEEVENTS__
  26. #include <AppleEvents.h>
  27. #endif
  28.  
  29. #ifndef __CONTROLDEFINITIONS__
  30. #include <ControlDefinitions.h>
  31. #endif
  32.  
  33. #ifndef __DEVICES__
  34. #include <Devices.h>
  35. #endif
  36.  
  37. #ifndef __DIALOGS__
  38. #include <Dialogs.h>
  39. #endif
  40.  
  41. #ifndef __DISKINIT__
  42. #include <DiskInit.h>
  43. #endif
  44.  
  45. #ifndef __FIXMATH__
  46. #include <FixMath.h>
  47. #endif
  48.  
  49. #ifndef __FONTS__
  50. #include <Fonts.h>
  51. #endif
  52.  
  53. #ifndef __MACMEMORY__
  54. #include <MacMemory.h>
  55. #endif
  56.  
  57. #ifndef __MENUS__
  58. #include <Menus.h>
  59. #endif
  60.  
  61. #ifndef __MOVIES__
  62. #include <Movies.h>
  63. #endif
  64.  
  65. #ifndef __PROCESSES__
  66. #include <Processes.h>
  67. #endif
  68.  
  69. #ifndef __QUICKTIMECOMPONENTS__
  70. #include <QuickTimeComponents.h>
  71. #endif
  72.  
  73. #ifndef __QUICKTIMEVR__
  74. #include <QuickTimeVR.h>
  75. #endif
  76.  
  77. #ifndef __RESOURCES__
  78. #include <Resources.h>
  79. #endif
  80.  
  81. #ifndef __SEGLOAD__
  82. #include <SegLoad.h>
  83. #endif
  84.  
  85. #ifndef __SOUND__
  86. #include <Sound.h>
  87. #endif
  88.  
  89. #ifndef __TEXTUTILS__
  90. #include <TextUtils.h>
  91. #endif
  92.  
  93. #ifndef __TOOLUTILS__
  94. #include <ToolUtils.h>
  95. #endif
  96.  
  97. #ifndef __TRAPS__
  98. #include <Traps.h>
  99. #endif
  100.  
  101. #ifndef __QTUtilities__
  102. #include "QTUtilities.h"
  103. #endif
  104.  
  105. #include <stdio.h>
  106. #include <string.h>
  107.  
  108.  
  109. //////////
  110. //
  111. // constants
  112. //
  113. //////////
  114.  
  115. #define kEmergencyMemorySize        40*1024L        // size of the block of memory used for our grow zone procedure
  116. #define kExtraStackSpaceSize        32*1024L        // amount of additional stack space
  117.  
  118. #define kBroughtToFront                3                // number of times to call EventAvail at application startup
  119.  
  120. #define kNewMovieName                "untitled.mov"    // default name of a movie created by "New" menu command
  121.  
  122. #define kInvalidFileRefNum            -1                // an invalid file reference number
  123.  
  124. enum {
  125.     kMovieControllerObject          = FOUR_CHAR_CODE('MCvr')
  126. };
  127.  
  128. // for menus
  129. enum eMenubar { 
  130.     mMenubar        = 128
  131. };
  132.  
  133. enum eMainMenus {
  134.     mApple            = 128,
  135.     mFile,
  136.     mEdit
  137. };
  138.  
  139. enum  eAppleMenu {
  140.     iAbout            = 1
  141. };
  142.  
  143. enum eFileMenu {
  144.     iNew            = 1,
  145.     iOpen,
  146.     iClose,
  147.     iSave,
  148.     iSaveAs,
  149.     iPrint            = 7,
  150.     iQuit            = 9
  151. };
  152.  
  153. enum eEditMenu {
  154.     iUndo            = 1,
  155.     iCut            = 3,
  156.     iCopy,
  157.     iPaste,
  158.     iClear,
  159.     iSelectAll        = 8,
  160.     iPreferences    = 10
  161. };
  162.  
  163. // for dialogs
  164. enum eDialogs {
  165.     kAboutBoxID                        = 128,                    // dialog ID for About box
  166.     kAlertErrorID                    = 129,                    // dialog ID for warning box
  167.     kSaveDialogID                    = 130                    // dialog ID for "Save changes..." dialog box
  168. };
  169.  
  170. // items in these dialogs
  171. #define kSaveChanges                1                        // save the changes before closing window
  172. #define kCancelClose                2                        // no, don't close the window or save changes
  173. #define kDontSaveChanges            3                        // discard any unsaved changes
  174.  
  175.  
  176. #define kOKButtonUserItem            4
  177.  
  178. // constants for standard modal dialog filter proc
  179. #define kMyButtonDelay                8
  180. #define kReturnKey                    (char)0x0D    
  181. #define kEnterKey                    (char)0x03    
  182. #define kEscapeKey                    (char)0x1B    
  183. #define kPeriod                        '.'
  184.  
  185. // constants for selecting InitApplication phase
  186. enum {
  187.     kInitAppPhase_BeforeCreateFrameWindow     = 1L << 0,        // MDI frame window windows not yet created
  188.     kInitAppPhase_AfterCreateFrameWindow    = 1L << 1,        // MDI frame window windows already created
  189.     kInitAppPhase_BothPhases                = kInitAppPhase_BeforeCreateFrameWindow | kInitAppPhase_AfterCreateFrameWindow
  190. };
  191.  
  192. // constants for selecting StopApplication phase
  193. enum {
  194.     kStopAppPhase_BeforeDestroyWindows         = 1L << 0,        // movie windows not yet torn down
  195.     kStopAppPhase_AfterDestroyWindows        = 1L << 1,        // movie windows already torn down
  196.     kStopAppPhase_BothPhases                = kStopAppPhase_BeforeDestroyWindows | kStopAppPhase_AfterDestroyWindows
  197. };
  198.  
  199. // parameters to the SetMenuItemState function
  200. #define kEnableMenuItem                0x00000000L
  201. #define kDisableMenuItem            0x00000001L
  202.  
  203. // resource ID for string resource containing application's name
  204. #define kAppNameResID                1000
  205. #define kAppNameResIndex            1
  206.  
  207. #define kDefaultWindowTitle            "\puntitled"
  208.  
  209.  
  210. /////////
  211. //
  212. // macros
  213. //
  214. //////////
  215.  
  216. // macros for converting Mac menu ID/menu item pairs into a single "menu item identifier"
  217. #define MENU_IDENTIFIER(menuID,menuItem)    ((menuID<<8)+(menuItem))
  218. #define MENU_ID(menuIdentifier)                ((menuIdentifier&0xff00)>>8)
  219. #define MENU_ITEM(menuIdentifier)            ((menuIdentifier&0x00ff))
  220.  
  221.  
  222. //////////
  223. //
  224. // data types
  225. //
  226. //////////
  227.  
  228. typedef MenuHandle            MenuReference;
  229. typedef WindowRef            WindowReference;
  230. typedef short                WORD;
  231.  
  232.  
  233. //////////
  234. //
  235. // structures
  236. //
  237. //////////
  238.  
  239. // WindowObjectRecord is a data structure attached to a movie window.
  240. // We use this structure to associate data with any window presented.
  241.  
  242. typedef struct {
  243.     WindowReference            fWindow;            // the window
  244.     OSType                    fObjectType;        // specific tag indicating that the window object belongs to our application
  245.     Movie                    fMovie;                // the main movie (QT or QTVR)
  246.     MovieController         fController;        // the movie controller for this window
  247.     FSSpec                    fFileFSSpec;        // location of the movie file
  248.     short                    fFileResID;
  249.     short                    fFileRefNum;
  250.     Boolean                    fCanResizeWindow;    // can the window be resized?
  251.     Boolean                    fDirty;                // has the movie data changed since the last save?
  252.     QTVRInstance            fInstance;            // the QTVRInstance
  253.     Handle                    fAppData;            // a handle to application-specific window data
  254. } WindowObjectRecord, *WindowObjectPtr, **WindowObject;
  255.  
  256.  
  257. //////////
  258. //
  259. // function prototypes
  260. //       
  261. //////////
  262.  
  263. void                        InitStack (long extraStackSpace);
  264. void                         InitMacEnvironment (long nMoreMasters);
  265. pascal long                    AppGrowZoneCallback (Size theBytesNeeded);
  266. Boolean                     InitMenubar (void);
  267. void                         MainEventLoop (void);
  268. void                         HandleMenuCommand (long theMenuResult);
  269. void                         AdjustMenus (void);
  270. void                         HandleKeyPress (EventRecord *theEvent);
  271. void                        QuitFramework (void);
  272.  
  273. Boolean                     DoCreateNewMovie (void);
  274. MovieController                SetupMovieWindowWithController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow);
  275. Boolean                     DoCreateMovieWindow (Movie theMovie, FSSpec *theFSSpec);
  276. void                         DoDestroyMovieWindow (WindowReference theWindow);
  277. OSErr                        DoSaveAsMovieFile (WindowReference theWindow);
  278. Boolean                     DoUpdateMovieFile (WindowReference theWindow);
  279. void                         DoActivateWindow (WindowReference theWindow, Boolean becomingActive);
  280. PASCAL_RTN void                StandardUserItemProcedure (DialogPtr theDialog, short theItem);
  281. PASCAL_RTN Boolean            StandardModalDialogEventFilter (DialogPtr theDialog, EventRecord *theEvent, short *theItemHit);
  282. Boolean                        CheckMovieControllers (EventRecord *theEvent);
  283.  
  284. Boolean                     IsAppWindow (WindowReference theWindow);
  285. Boolean                        IsDocWindow (WindowReference theWindow);
  286. WindowObject                 CreateWindowObject (WindowReference theWindow);
  287.  
  288. void                        SizeWindowToMovie (WindowObject theWindowObject);
  289. void                         ShowAboutBox (void);
  290. void                         ShowWarning (Str255 theMessage, OSErr theErr);
  291.  
  292. WindowReference                GetFrontMovieWindow (void);
  293. WindowReference                GetNextMovieWindow (WindowReference theWindow);
  294. WindowObject                GetWindowObjectFromFrontWindow (void);
  295. WindowObject                GetWindowObjectFromWindow (WindowReference theWindow);
  296. MovieController              GetMCFromFrontWindow (void);
  297. MovieController                GetMCFromWindow (WindowReference theWindow);
  298. QTVRInstance                GetQTVRInstanceFromFrontWindow (void);
  299. Handle                        GetAppDataFromFrontWindow (void);
  300. Handle                        GetAppDataFromWindow (WindowReference theWindow);
  301. Handle                        GetAppDataFromWindowObject (WindowObject theWindowObject);
  302. Boolean                     IsWindowObjectOurs (WindowObject theObject);
  303. void                        DoBeep (void);
  304. void                        SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  305. void                        SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  306. void                        SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText);
  307. void                        SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState);
  308. GrafPtr                        GetPortFromWindowReference (WindowReference theWindow);
  309. WindowReference                GetWindowReferenceFromPort (GrafPtr thePort);
  310. short                        GetWindowWidth (WindowReference theWindow);
  311. WindowReference                GetFrontAppWindow (void);
  312. WindowReference                GetNextAppWindow (WindowReference theWindow);
  313.  
  314.  
  315. // application-specific functions
  316. // These are defined in the ComApplication.c file;
  317. // you could override these to change the behavior of the function in a specific application.
  318. void                        InitApplication (UInt32 theStartPhase);
  319. void                        StopApplication (UInt32 theStopPhase);
  320. void                        DoIdle (WindowReference theWindow);
  321. void                        DoUpdateWindow (WindowReference theWindow, Rect *theRefrehArea);
  322. void                         HandleContentClick (WindowReference theWindow, EventRecord *theEvent);
  323. Boolean                        HandleApplicationKeyPress (char theCharCode);
  324. WindowRef                     CreateMovieWindow (Rect *theRect, Str255 theTitle);
  325. void                         HandleApplicationMenu (UInt16 theMenuItem);
  326. void                        AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu);
  327. Boolean                        DoApplicationEventLoopAction (EventRecord *theEvent);
  328. void                        AddControllerFunctionality (MovieController theMC);
  329. void                        InitApplicationWindowObject (WindowObject theWindowObject);
  330. void                        RemoveApplicationWindowObject (WindowObject theWindowObject);
  331. PASCAL_RTN Boolean            ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon);
  332.